<?php 
	/**
	 * 主程序，每日抓取最新数据，并提取和入库
	 */
	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	include_once dirname(dirname(__FILE__))."/zhenai/function.zhenai.php";
	$global_site = "zhenai";
	
	//抓取日期，默认为昨天
	$ymd =  date("Y-m-d", time()-60*60*24);
	if ($argc > 1) {
		$ymd = date("Y-m-d", strtotime($argv[1]));
	}
	
	//是否删除数据库中已经存在的数据
	if($argc > 2 && $argv[2] == "DELETE"){
		global $conn;
		$tblName = getTblname($ymd);
		$sql = "delete from $tblName where `from`='zhenai' and fetch_date='$ymd' ";
		$conn->query($sql);
	}
	
	$minId = getZhenaiMinId($ymd);
	$maxId = getZhenaiMaxId($ymd);
	$maxIdFinished = getZhenaiMaxIdFinished($ymd);
	printlog("yesterday min uid: $minId / max uid: $maxId / finished uid: $maxIdFinished", "main");
	$minId = ($maxIdFinished > $minId) ? $maxIdFinished : $minId; 
	
	//生成登录后的cookie
	//makeZhenaiCookie();
	
	//抓取，提取和入库
	//zhenai_crawl($minId, $maxId, $ymd);
	$page = file_get_contents('zhenai.html');	
	doWithZhenaiPage(28365404,$ymd,$page);

?>